package com.cvte.shop.service.rest;

import com.cvte.csb.core.interfaces.vo.RestResponse;
import com.cvte.shop.entity.dto.*;
import com.cvte.shop.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author DaiShubo
 * @version 1.0
 * @description 通用方法接口
 * @createTime 2020/8/4 9:39 上午
 * @since 1.7
 **/
@Api(tags = "通用方法接口")
@RestController
public class RestUniversalMethodController {

    @Autowired
    private UniversalTableConfigService universalTableConfigService;

    @Autowired
    private UniversalMethodResultService universalMethodResultService ;

    @Autowired
    private UniversalMethodConfigService universalMethodConfigService;

    @Autowired
    private UniversalViewConfigService universalViewConfigService;



    /**
     * 添加配置表的信息
     *
     * @return
     */
    @ApiOperation("配置表信息")
    @PostMapping("/add_table_config")
    public RestResponse addTableConfig(@RequestBody TableDTO tableDTO) {
        return universalTableConfigService.addTableConfig(tableDTO);
    }


    /**
     * 添加配置条件的信息
     * @param conditionDTO
     * @return
     */
    @ApiOperation("配置条件信息")
    @PostMapping("/add_condition")
    public RestResponse addCondition(@RequestBody ConditionDTO conditionDTO){
        return universalTableConfigService.addCondition(conditionDTO);
    }

    /**
     * 配置方法的接口
     * @return
     */
    @ApiOperation("配置方法信息")
    @PostMapping("add_method_config")
    public RestResponse addMethodConfig(@RequestBody MethodDTO methodDTO){
        return universalMethodConfigService.addMethodConfig(methodDTO);
    }

    /**
     * 配置视图信息
     * @return tableId      表的id
     */
    @ApiOperation("添加视图信息")
    @PostMapping("add_view_config")
    public RestResponse addViewConfig(@RequestBody ViewDTO viewDTO){
        return universalViewConfigService.addViewConfig(viewDTO);
    }

    /**
     *
     * 添加视图条件配置信息
     * @param conditionDTO
     * @return
     */
    @ApiOperation("添加视图条件信息")
    @PostMapping("add_view_condition_config")
    public RestResponse addViewConditionConfig(@RequestBody ConditionDTO conditionDTO){
        return universalTableConfigService.addCondition(conditionDTO);
    }

    /**
     * 通用方法
     * @param viewId        视图的id
     * @param request       请求
     * @return
     */
    @ApiOperation("通用方法")
    @RequestMapping("universalMethod/**")
    public RestResponse universalMethod(String viewId, HttpServletRequest request){
        return universalMethodResultService.universalMethod(viewId,request);
    }

}
